/**
 * 硫粉
 */
S = Widget.extend({
	ctor:function(){
		this._super();
		this.init();
		this.setTag(TAG_SS);
	},
	init:function(){
		this.body = new Button(this, 10, TAG_SS_BOTTLE, "#s_bottle.png", this.callback);

		var lid = new Button(this, 10, TAG_SS_LID, "#lid.png", this.callback);
		lid.setPosition(0,40);

		var spoon = new Button(this, 8, TAG_SS_SPOON, "#spoon.png", this.callback);
		spoon.setPosition(150,0);

		var label = new cc.LabelTTF("硫粉",gg.fontName,12);
		label.setColor(cc.color(0,0,0));
		label.setPosition(25, 41);
		this.body.setCascadeOpacityEnabled(true);
		this.body.addChild(label, 11);
		
		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callNext.retain();
	},
	openLid:function(){
		var ber = cc.bezierBy(1.5,[cc.p(50,70),cc.p(60,-70),cc.p(60,-75)]);
		var rotate = cc.rotateTo(1.5, 180);
		var spawn = cc.spawn(ber, rotate);
		var seq = cc.sequence(spawn,this.func);
		this.getChildByTag(TAG_SS_LID).runAction(seq);
	},
	rotateBody:function(obj){
		var rotate1 = cc.rotateTo(1,65);
		var delay = cc.delayTime(0.8);
		var rotate2 = cc.rotateTo(1,0);
		var seq = cc.sequence(cc.delayTime(1.5),rotate1,delay,rotate2);
		obj.runAction(seq);
	},
	callback:function(p){
		switch(p.getTag()){
//		case TAG_LID:

//		break;
		case TAG_SS_SPOON:
			this.openLid();
			var move1 = cc.moveTo(0.4,cc.p(100, 50));
			var rotate = cc.rotateTo(0.2,15);
			var move2 = cc.moveTo(0.4,cc.p(30,20));
			var delay = cc.delayTime(0.8);
			var move3 = cc.moveTo(0.5,cc.p(100,50));
			var move4= cc.moveTo(0.6, cc.p(234,172));
			var seq = cc.sequence(cc.delayTime(1.5),move1,rotate,move2,delay,cc.callFunc(function(){
				p.setSpriteFrame("spoon4.png");
			},this),move3,move4,this.func);
			p.runAction(seq);
			this.rotateBody(this.body);
			break;
		}
	},
	actionDone:function(p){
		switch(p.getTag()){
//		case TAG_LID:
//		p.setRotation(0);
//		p.setSpriteFrame("lid2.png");
//		gg.flow.next();
//		break;
		case TAG_SS_SPOON:
			this.setCascadeOpacityEnabled(true);
			p.setSpriteFrame("spoon.png");
			var s=this.getParent().getChildByTag(TAG_PAPER).getChildByTag(TAG_FILTER).getChildByTag(TAG_FILTER_S);
			s.setOpacity(255);
			var mov=cc.moveTo(1, cc.p(55, 30));
			var sca=cc.scaleTo(1, 2,1);
			var spa=cc.spawn(mov,sca);
			var mov1=cc.moveTo(0.6, cc.p(35,30));
			var mov2=cc.moveTo(0.6, cc.p(50,30));
			var seq=cc.sequence(spa,cc.callFunc(function() {
				p.setSpriteFrame("spoon5.png");
				p.setRotation(95);
				var move1=cc.moveTo(0.6, cc.p(240,143));
				var move2=cc.moveTo(0.6, cc.p(210,143));
				p.runAction(cc.sequence(move1,move2,move1,move2,move1));
			}, this),cc.delayTime(0.6),cc.callFunc(function() {
				var fe=this.getParent().getChildByTag(TAG_PAPER).getChildByTag(TAG_FILTER).getChildByTag(TAG_FILTER_FE);
				fe.runAction(cc.sequence(cc.moveTo(0.6, cc.p(35,30)),cc.moveTo(0.6, cc.p(47,30))));
			}, this),mov1,mov2,mov1,mov2,cc.callFunc(function() {
				this.removeFromParent();
				gg.flow.next();
			}, this));
			s.runAction(seq);

			break;
		}
	},
	onExit:function(){
		this._super();
		this.callNext.release();
	}
});